// pages/wl01/wl01.js
import Page from '../../common/page';
/* import request from '../../utils/request' */
import Notify from '../../miniprogram_npm/@vant/weapp/notify/notify';
const api = require("../../utils/app.js")

//1是重要端口命名，没有序号是 重要设备命名规范
var arr = [];
var arr1 = [];
Page({

    /**
     * 页面的初始数据
     */
    data: {
        option1: [{
                text: '选择选项',
                value: 0
            },
            {
                text: '正常',
                value: 1
            },
            {
                text: '异常',
                value: 2
            },
            {
                text: '故障',
                value: 3
            },
            {
                text: '其他',
                value: 4
            },
        ],
        value1: 0,
        infolist: [],
        checked: false,
        infoportlist: [],
        jianchalist: [],
        jianchalist1: []
    },

    xuanze1(a) {
        let jiancha = a.currentTarget.dataset.id - 1;
        arr1[jiancha] = a.detail
        this.setData({
            jianchalist1: arr1
        })
    },

    xuanze(a) {
        let jiancha = a.currentTarget.dataset.id - 1;
        arr[jiancha] = a.detail
        this.setData({
            jianchalist: arr
        })
    },

    onChange({
        detail
    }) {
        // 需要手动对 checked 状态进行更新
        if (detail == true) {
            this.setData({
                value1: 1
            })
            for (let i = 0; i < this.data.infolist.length; i++) {
                arr[i] = 1;
            }

            for (let i = 0; i < this.data.infoportlist.length; i++) {
                arr1[i] = 1;
            }
        } else {
            this.setData({
                value1: 0
            })
            for (let i = 0; i < this.data.infolist.length; i++) {
                arr[i] = 0;
            }

            for (let i = 0; i < this.data.infoportlist.length; i++) {
                arr1[i] = 0;
            }
        }

        this.setData({
            checked: detail,
            jianchalist: arr,
            jianchalist1: arr1
        });
    },

    /* 提交 消息顶部显示 */
    btnSub() {
        Notify({
            type: 'success',
            message: '提交成功'
        });
    },

    /* 发送数据到java */
    gojava(e) {
        console.log(e)
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        api.getInfo("/wlequipment/list").then(res => {
            let infolist = res.page.list;
            this.setData({
                infolist
            });
        })
        api.getInfo("/wlport/list").then(res => {
            let infoportlist = res.page.list;
            this.setData({
                infoportlist
            })
        })


    },

    gojava(e) {
        console.log(e.detail.value)
        var shuju = {
            "arrshebei": arr.toString(),
            "arrport": arr1.toString(),
            "shit": e.detail.value
        };
        api.postInfo("/testJson3", JSON.stringify(shuju)).then(res => {
            console.log(res)
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})